import RPi.GPIO as GPIO

class Signal:

    def __init__(self):
        
        self.backward = 17
        self.forward = 18
        self.left = 22
        self.right = 23
        self.power_on = 25
    
        #Initialize GPIO ports
        GPIO.setmode(GPIO.BCM)
    
        GPIO.setup(self.backward,GPIO.OUT) 
        GPIO.setup(self.forward,GPIO.OUT) 
        GPIO.setup(self.left,GPIO.OUT) 
        GPIO.setup(self.right,GPIO.OUT) 
        GPIO.setup(self.power_on,GPIO.OUT) 
        
        #Set all ports to low
        self.stop()
        self.power(0)
 
    def stop(self):
        #Set everything to low
        GPIO.output(self.backward,False)
        GPIO.output(self.forward,False)
        GPIO.output(self.left,False)
        GPIO.output(self.right,False)

    def power(self,switch):
        if switch:
            GPIO.output(self.power_on,True)
        else:
            GPIO.output(self.power_on,False)
    
    def y_movement(self,switch):
        
        fwdFlag = False
        bckFlag = False
        if switch>0:  
            fwdFlag = True
        elif switch <0:
            bckFlag = True

        GPIO.output(self.backward,fwdFlag)
        GPIO.output(self.forward,bckFlag)
 
    def x_movement(self,switch):
        
        rgtFlag = False
        lftFlag = False
        if switch>0:  
            rgtFlag = True
        elif switch <0:
            lftFlag = True

        GPIO.output(self.left,lftFlag)
        GPIO.output(self.right,rgtFlag)
    
